* This file: C:\Rehm\Articles\Electoral_Studies\robin_best\robin_best.do

cd "C:\Rehm\Articles\Electoral_Studies\"
use if inrange(year,1972,2004) using polarization.dta, clear

cd "C:\Rehm\Articles\Electoral_Studies\robin_best/"

* Sample for figure 5 in the paper (data quality is highest)
gen sample_figure5=inlist(ccode,900,20,385,390,2,200,380,255,920)
drop if ccode==350

local alpha=1
keep sample ccode year N_parties adj_P_self_`alpha' adj_P_party_`alpha' adj_P_expert_`alpha'
label var adj_P_self_1 "ER polarization (alpha=1), constituency"
label var adj_P_party_1 "ER polarization (alpha=1), perception"
label var adj_P_expert_1 "ER polarization (alpha=1), experts"

decode ccode, gen(CCODE)
label var CCODE "Country identifier (string)"

order sample ccode CCODE year N_parties

note: Philipp Rehm, rehm.ph@gmail.com, October 28, 2011
note: Philipp Rehm and Timothy Reilly, �United we stand: Constituency homogeneity and comparative party polarization,� Electoral Studies 29, no. 1 (March 2010): 40-53.

compress
saveold robin_best_polarization.dta, replace

** Figures
* The following is a version of Figure 5 that includes more countries.
* I can't really guarantee the data quality for the countries that are not in Figure 5...
local alpha=1
twoway ///
	(line adj_P_self_`alpha' year, sort lp(solid) lw(medthick)) ///
	(line adj_P_party_`alpha' year, sort lp(dot) lw(medthick)) ///
	(line adj_P_expert_`alpha' year, sort lp(dash) lw(medthick)) ///
	, by(CCODE, note("", size(vsmall)) title("") iscale(*0.9)) ///
	scheme(s2manual) ///
	xlabel(1970 (10) 2000,labsize(small)) ///
	ylabel(0 (0.04) 0.12,labsize(small)) ///
	xscale(range(1972 2004)) ///
	ylabel(, angle(0) format(%9.2f) tp(i) labsize(small)) ///
	xtitle("") ///
	ytitle("ER-polarization", size(small)) ///
	legend(r(1) c(3) label(1 "Constituency") label(2 "Perception") ///
	label(3 "Experts") size(small))
graph export polarization_many_countries.tif, replace
graph export polarization_many_countries.pdf, replace

* The following is Figure 5 in the paper
keep if sample_figure5==1
twoway ///
	(line adj_P_self_`alpha' year, sort lp(solid) lw(medthick)) ///
	(line adj_P_party_`alpha' year, sort lp(dot) lw(medthick)) ///
	(line adj_P_expert_`alpha' year, sort lp(dash) lw(medthick)) ///
	, by(CCODE, note("", size(vsmall)) title("") iscale(*0.9)) ///
	scheme(s2manual) ///
	xlabel(1970 (10) 2000,labsize(small)) ///
	ylabel(0 (0.04) 0.12,labsize(small)) ///
	xscale(range(1972 2004)) ///
	ylabel(, angle(0) format(%9.2f) tp(i) labsize(small)) ///
	xtitle("") ///
	ytitle("ER-polarization", size(small)) ///
	legend(r(1) c(3) label(1 "Constituency") label(2 "Perception") ///
	label(3 "Experts") size(small))
graph export polarization_few_countries.tif, replace
graph export polarization_few_countries.pdf, replace

	

